// pages/testSituation/testSituation.js
const app = getApp();
import api from '../../utils/api.js';

Page({

  /**
   * 页面的初始数据
   */
  data: {
  },

  // 练习
  getTestInfo(){
    // wx.showLoading({
    //   title: '加载中',
    // })
    api.POST('applet/customerPaper/finds', { paper_id: this.data.paper_id},
    res=>{
      console.log(res)
      this.setData({
        withoutNum: res.data.withoutNum,
        errorNum: res.data.errorNum,
        // lastTime: res.data.last_timing
      })

      if (this.data.totalNum != this.data.withoutNum) {
        this.setData({
          isShow: true
        })
      } else if (this.data.totalNum == this.data.withoutNum) {
        this.setData({
          isShow: false
        })
      }
      // wx.hideLoading()
    })
  },

  
  goToTestDetail(e){

    wx.navigateTo({
      url: '/pages/testDetail/testDetail?paper_id=' + this.data.paper_id + '&status=' + e.currentTarget.dataset.status + '&type=1' + '&totalNum=' + this.data.totalNum + '&withoutNum=' + this.data.withoutNum + '&name=' + this.data.name,
    })
  },

  

  goToRealTestDetail(e){
    // wx.navigateTo({
    //   url: '/pages/realTestDetail/realTestDetail?status=' + e.currentTarget.dataset.status + '&lastTime=' + this.data.lastTime
    // })
    wx.redirectTo({
      url: '/pages/realTestDetail/realTestDetail?status=' + e.currentTarget.dataset.status
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let obj = app.globalData.test
    console.log(obj)
    this.setData({
      type: obj.type,
      paper_id: obj.paper_id,
      totalNum: obj.totalNum,
      timing: obj.timing,
      lastTime: obj.lastTime,
      name: obj.name,
      paper_name: obj.paper_name,
      subjectNum: obj.subjectNum,
      paper_category_id: obj.paper_category_id,

      userInfo: app.globalData.userInfo

    })
    
    if(this.data.type == 1){
      wx.setNavigationBarTitle({
        title: '练习题',
      })
    }else{
      wx.setNavigationBarTitle({
        title: this.data.name,
      })
    }
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getTestInfo()

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})